//
//  CityRecorderController.m
//  AppFrame
//
//  Created by GXJ on 2017/3/6.
//  Copyright © 2017年 GXJ. All rights reserved.
//

#import "CityRecorderController.h"
#import "CityRecorderInfoController.h"
#import "GXJPagesViewController.h"
#import "CityRecorderObj.h"
@interface CityRecorderController ()

@end

@implementation CityRecorderController
{
    NSArray *array;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"新闻详情";
    self.view.backgroundColor = [UIColor whiteColor];
    [self requestCityNewData];
}

- (void) createHeaderTitle{
    //要添加的子视图
    NSMutableArray *viewArr = [[NSMutableArray alloc]init];
    array = @[@"推荐",@"都市",@"政务"];
    for (int i = 0 ; i<self.titleArray.count; i++) {
        CityRecorderInfoController *vc = [CityRecorderInfoController new];
        //vc.title = _titleArray[i];//必选
        CityRecorderObj *obj = self.titleArray[i];
        vc.title = obj.name;//必选
        vc.indexNum = obj.ID;
        [viewArr addObject:vc];
    }
    
    GXJPagesViewController *control = [[GXJPagesViewController alloc]init];
    if (self.titleArray.count<6) {
        control.onepageNumber = self.titleArray.count;
    } else {
        control.onepageNumber = 6;
    }
    control.controllersArr = viewArr;
    control.titleType = SCROLLTYPE;//设置头部效果
    [self addChildViewController:control];
    [self.view addSubview:control.view];
}

- (void) requestCityNewData {

    __weak __typeof(self) weakSelf = self;
    [DDNetWorkManager categoryCityNewsWithController:weakSelf success:^(id result, DDcacheType cacheType, DDresultType resultType) {
        [DDHudHelper showHudWithResult:result resultSuccess:^{
            self.titleArray = [CityRecorderObj objectArrayWithKeyValuesArray:result[@"data"][@"categoryList"]];
            //NSLog(@"%ld",self.titleArray.count);
            [self createHeaderTitle];
        }];
    } failure:^(NSError *error) {
        
        [SVProgressHUD showErrorWithStatus:NSLocalString(@"网络错误")];
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
